<?php
/**
 * SocialEngine
 *
 * @category   Application_Extensions
 * @package    Page
 * @copyright  Copyright Hire-Experts LLC
 * @license    http://www.hire-experts.com
 * @version    $Id: index.tpl 2010-08-31 17:53 idris $
 * @author     Idris
 */
?>

<script type="text/javascript">
function multiDelete()
{
  return confirm('<?php echo $this->string()->escapeJavascript($this->translate("Are you sure you want to delete the selected pages?")) ?>');
}

function selectAll()
{
  var i;
  var multidelete_form = $('multidelete_form');
  var inputs = multidelete_form.elements;
  for (i = 1; i < inputs.length; i++) {
    if (!inputs[i].disabled) {
      inputs[i].checked = inputs[0].checked;
    }
  }
}

function confirmDelete(page_id)
{
  if (confirm('<?php echo $this->string()->escapeJavascript($this->translate("Are you sure you want to delete this page?")) ?>')){
	  window.location.href = '<?php echo $this->url(array('action' => 'delete'), 'page_admin_manage', true); ?>/'+page_id;
  }else{
	  return false;
  }
}

var currentOrder = '<?php echo $this->order ?>';
var currentOrderDirection = '<?php echo $this->order_direction ?>';

var changeOrder = function(order, default_direction){
  if( order == currentOrder ) {
    $('order_direction').value = ( currentOrderDirection == 'ASC' ? 'DESC' : 'ASC' );
  } else {
    $('order').value = order;
    $('order_direction').value = default_direction;
  }
  $('filter_form').submit();
}

</script>

<h2><?php echo $this->translate("Page Plugin") ?></h2>

<?php if( count($this->navigation) ): ?>
  <div class='tabs'>
    <?php
      // Render the menu
      //->setUlClass()
      echo $this->navigation()->menu()->setContainer($this->navigation)->render();
    ?>
  </div>
<?php endif; ?>

<p>
  <?php echo $this->translate("This is a list all pages created by your users. You can approve, disapprove or delete them. Use form to filter pages.") ?>
</p>
<br />

<div class='admin_search'>
	<?php echo $this->filterForm->render($this); ?>
</div>
<br />

<div class='admin_results'>
  <div>
    <?php $pageCount = $this->paginator->getTotalItemCount() ?>
    <?php echo $this->translate(array("%s page found", "%s pages found", $pageCount), ($pageCount)) ?>
  </div>
  <div>
    <?php echo $this->paginationControl($this->paginator); ?>
  </div>
</div>
<br />
	
<?php if( count($this->paginator) ): ?>
  <form id='multidelete_form' method="post" action="<?php echo $this->url(array('module' => 'page', 'controller' => 'manage', 'action' => 'delete-all'), 'admin_default');?>" onSubmit="return multiDelete();">
    <table class='admin_table'>
      <thead>
        <tr>
          <th class='admin_table_short'><input onclick='selectAll();' type='checkbox' class='checkbox' /></th>
          <th class='admin_table_short'><a href="javascript:void(0);" onclick="javascript:changeOrder('page_id', 'DESC');">ID</a></th>
          <th><a href="javascript:void(0);" onclick="javascript:changeOrder('title', 'ASC');"><?php echo $this->translate("Title") ?></a></th>
          <th><a href="javascript:void(0);" onclick="javascript:changeOrder('category', 'ASC');"><?php echo $this->translate("Category") ?></a></th>
          <th><?php echo $this->translate("Owner") ?></th>
          <th><a href="javascript:void(0);" onclick="javascript:changeOrder('view_count', 'ASC');"><?php echo $this->translate("Views") ?></a></th>
          <th><a href="javascript:void(0);" onclick="javascript:changeOrder('modified_date', 'ASC');"><?php echo $this->translate("Date") ?></a></th>
          <th><?php echo $this->translate("Options") ?></th>
        </tr>
      </thead>
      <tbody>
        <?php foreach ($this->paginator as $item): ?>
          <tr class="<?php if ($item->featured) echo "admin_featured_page"; ?>">
            <td><input type='checkbox' name='delete[]' class='checkbox' value="<?php echo $item->page_id ?>"/></td>
            <td><?php echo $item->getIdentity() ?></td>
            <td><?php echo $this->htmlLink($item->getHref(), ($item->getTitle() ? $item->getTitle() : "<i>".$this->translate("Untitled")."</i>" )); ?></td>
            <td><?php echo ($item->category ? $item->category : ("<i>".$this->translate("Uncategorized")."</i>")); ?></td>
            <td><?php echo $this->htmlLink($this->user($item->user_id)->getHref(), $this->user($item->user_id)->getTitle()); ?></td>
            <td><?php echo $this->locale()->toNumber($item->view_count) ?></td>
            <td><?php echo $item->creation_date ?></td>
            <td>
            <?php echo $this->htmlLink($item->getHref(), $this->translate('view')); ?>
              |
              <?php echo $this->htmlLink(
                'javascript:void(0)',
                $this->translate('delete'),
                array('onClick' => "confirmDelete({$item->getIdentity()})"
              )) ?>
              |
              <?php
              if ($item->approved == 0){
               	echo $this->htmlLink(
                array('route' => 'admin_default', 'module' => 'page', 'controller' => 'manage', 'action' => 'approve', 'value' => 1, 'id' => $item->page_id), $this->translate('approve'));
							}else{
								echo $this->htmlLink(
                array('route' => 'admin_default', 'module' => 'page', 'controller' => 'manage', 'action' => 'approve', 'value' => 0, 'id' => $item->page_id), $this->translate('disapprove'));
							}
              ?>
              |
              <?php
              if ($item->featured == 0){
               	echo $this->htmlLink(
                array('route' => 'admin_default', 'module' => 'page', 'controller' => 'manage', 'action' => 'feature', 'value' => 1, 'id' => $item->page_id), $this->translate('set featured'));
							}else{
								echo $this->htmlLink(
                array('route' => 'admin_default', 'module' => 'page', 'controller' => 'manage', 'action' => 'feature', 'value' => 0, 'id' => $item->page_id), $this->translate('set usual'));
							}
              ?>
            </td>
          </tr>
        <?php endforeach; ?>
      </tbody>
    </table>
      <br />

    <div class='buttons'>
      <button type='submit'><?php echo $this->translate("Delete Selected") ?></button>
    </div>
  </form>
  
<?php else:?>
  <div class="tip">
    <span>
      <?php echo $this->translate("pages_admin there are no pages") ?>
    </span>
  </div>
<?php endif; ?>